﻿@model List<NoticeView>
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Title = "公告管理";
}
<div class="content-right date-wrap fl c">

    <div class="search mt5">
        <form class="layui-form" method="post">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">公告标题 : </label>
                    <div class="layui-input-inline"><input type="text" name="Name" id="Name" placeholder="请输入公告标题" autocomplete="off" class="layui-input" value="@ViewBag.Name" /></div>
                </div>
                <input type="submit" class="layui-btn layui-btn-radius layui-btn-warm" lay-filter="search" value="搜 索" />
            </div>
        </form>
    </div>
    <div class="main mt5">
        <div class="btns">
            <a href="javascript:;" data-module="TypeDictionary" data-right="add" id="add" class="checkright">发 布</a>
            <a href="javascript:;" data-module="TypeDictionary" data-right="delete" id="delete" class="checkright">删 除</a>
        </div>
        <div class="layui-form">
            <table class="layui-table" style="word-break:break-all;word-wrap:break-word">
                <thead>
                    <tr>
                        <th width="4%" class="table-center">
                            <input type="checkbox" lay-skin="primary" lay-filter="allChoose" />
                            <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>
                        </th>
                        <th width="4" style="text-align:center">序号</th>
                        <th width="13" style="text-align:center">标题</th>
                        <th width="13" style="text-align:center">内容</th>
                        <th width="10" style="text-align:center">接受项目</th>
                        <th width="10" style="text-align:center">接受单位</th>
                        <th width="8" style="text-align:center">接受人员</th>
                        <th width="8" style="text-align:center">发布途径</th>
                        <th width="8" style="text-align:center">发布人</th>
                        <th width="9" style="text-align:center">发布时间</th>

                    </tr>
                </thead>
                <tbody>
                    @if (Model != null && Model.Count() > 0)
                    {
                        for (int i = 0; i < Model.Count; i++)
                        {
                            NoticeView notice = Model[i];
                            <tr>
                                <td style="text-align:center">
                                    <input type="checkbox" lay-skin="primary" />
                                    <input type="hidden" name="ids" id="id-@notice.SId" value="@notice.SId" />
                                </td>
                                <td class="table-center">@(i+1)</td>
                                <td class="table-center">@notice.Title</td>
                                <td class="table-center">@notice.Content</td>
                                <td class="table-center">@notice.ProjectNames</td>
                                <td class="table-center">@notice.CompanyNames</td>
                                <td class="table-center">@notice.UserNames</td>
                                <td class="table-center">
                                    @switch (notice.WayOfRelease)
                                        {
                                            case 3:
                                        @:pc,app
                                                break;
                                            case 1:
                                        @:pc
                                                break;
                                            case 2:
                                        @:app
                                                break;
                                            default:
                                        @:无
                                                break;
                                        }

                                </td>
                                <td class="table-center">@notice.SendUserName</td>
                                <td class="table-center">@notice.SendTime</td>

                            </tr>
                        }
                    }
                    else
                    {
                        <tr>
                            <td colspan="11" class="table-center">
                                暂无数据
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>

        <div id="page"></div>
    </div>

</div>
<script type="text/javascript">
    //增加
    $("#add").click(function () {
        parent.layer.open({
            type: 2,
            title: GetLayerTitle("公告管理-添加"),
            shadeClose: false, //点击遮罩关闭层
            area: [BigLayerWidth, BigLayerWidth],
            content: ['/Notice/Add','no']
        });
    });


    //隐藏分页
    if ('@ViewBag.Total' == 0) {
        $("#page").hide();
    }

    layui.use(['layer', 'form', 'element', 'laypage'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;
           //分页
        laypage.render({
            elem: 'page',
            count: @ViewBag.Total,
            curr:@ViewBag.pageIndex,
            layout: ['prev', 'page', 'next', 'skip','count', ],
            jump:function(obj,first){
                if (!first){
                    //得到了当前页，用于向服务端请求对应数据
                    var curr = obj.curr;
                    var search = $("form").serialize();
                    window.location.href = "/Notice/Index?pageIndex=" + curr + "&" + search;
                }
            }
        });
        //全选
        form.on('checkbox(allChoose)', function (data) {
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
        //删除
        $("#delete").click(function () {
            var chkItems = $('.layui-table tbody input[type="checkbox"]:checked');
            var ids = "";
            chkItems.each(function (index, item) {
                var hfId = $(this).parent().find("input[type='hidden']");
                ids += hfId.val() + ",";
            });
            if (ids != "") {
                parent.layer.confirm("确认要删除所选择的项？",{icon:3},function(){
                    $.post("Delete",{ids:ids,belong:'@ViewBag.Belong'},function(data){
                        if(data.Flag){
                            parent.layer.msg("删除成功",{time:1000,icon:1});
                            var search = $("form").serialize();
                            window.location.href = "/Notice/Index?pageIndex=1&" + search;
                        }else{
                            parent.layer.alert(data.Message, { icon: 2 });
                        }
                    },"json");
                },function(){
                    return;
                })

            }else {
                parent.layer.alert("请先选择要删除的数据", { icon: 2 });
            }
        });
    });
</script>
